package edu.mse.camel.client.posterboard.ui.actions;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.FileEditorInput;

import edu.mse.camel.client.posterboard.ui.PosterboardPlugin;
import edu.mse.camel.client.posterboard.ui.editor.EditorUtil;
import edu.mse.camel.client.posterboard.ui.editor.PosterBoardEditor;
import edu.mse.camel.client.session.team.TEAMMEMBER_STATUS;
import edu.mse.camel.client.session.team.TeamList;
/**
 * @author darpan
 *
 */
public class OpenPBInCollabEditorAsTargetAction extends OpenPBInCollabEditorAction {

	@Override
	public void run(IAction action) {
		if (TeamList.getInstance().getMyStatus().equals(TEAMMEMBER_STATUS.OFFLINE)) {
			ErrorDialog ed = new ErrorDialog(new Shell(),
					"Error",
					"Please Login first", new Status(IStatus.ERROR,
							PosterboardPlugin.PLUGIN_ID,
							"Please Login first"), IStatus.ERROR);
			ed.open();
			return;
		}
		if (TeamList.getInstance().getMyStatus().equals(TEAMMEMBER_STATUS.ONLINE)) {
			ErrorDialog ed = new ErrorDialog(new Shell(),
					"Error",
					"Please join a session first", new Status(IStatus.ERROR,
							PosterboardPlugin.PLUGIN_ID,
							"Please join a session first"), IStatus.ERROR);
			ed.open();
			return;
		}
		
		String id = PosterBoardEditor.ID;
		try {
			EditorUtil.openEditor(
					page,
					new FileEditorInput(iFile), 
					id);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
		// TODO Auto-generated method stub
		
	}
	
}
